package com.ykzb.project.controller;

import com.ykzb.base.bean.ResultBean;
import com.ykzb.constants.UrlConstants;
import com.ykzb.project.model.ProjectInfo;
import com.ykzb.project.service.IProjectService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by mac on 2017/3/30.
 */
@Controller
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private IProjectService projectService;

    /**
     * 进入项目中心
     * @return
     */
    @RequestMapping(value = UrlConstants.PROJECT_TO_CENTER, method ={RequestMethod.POST,RequestMethod.GET})
    public ModelAndView toProjectCenter(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("projectCenter");
        return mv;
    }

    /**
     * 进入项目详情
     * @return
     */
    @RequestMapping(value = UrlConstants.PROJECT_INFO, method ={RequestMethod.POST,RequestMethod.GET})
    public ModelAndView toProjectInfo(String projectId) throws Exception{
        ModelMap model =  projectService.toProjectInfo(projectId);
        return new ModelAndView("projectInfo",model);
    }

    /**
     *
     * @param minMoney  最小金额
     * @param maxMoney  最大金额
     * @param state     项目状态
     * @param classify  分类名称
     * @param currPage  当前页
     * @param pageSize  每页条数
     * @return
     */
    @RequestMapping(value = UrlConstants.PROJECT_SEARCH, method ={RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public ResultBean searchProject(String minMoney, String maxMoney, String state, String classify, String currPage, String pageSize) {
        ResultBean ret  = projectService.searchProject(minMoney, maxMoney, state,  classify,  currPage, pageSize);
        return ret;
    }

}
